// 退出游戏
export const desc = {
    "name": "退出游戏",
    "desc": "主动退出游戏",
    "params_type": "无",
    "params": [],
    "returns": [],
    "example": 'JGESDK:发送(5)'
}
// @ts-ignore
export async function execute(client_id,message_json) {
    let login_characters = G.Characters.get_current_login_characters(client_id);
    if(_FightDataCache.has(login_characters["战斗开关"])){
        ClientUtils.send_basic_prompt(client_id,"#R战斗中！,禁止退出游戏！");
    }
    let username = _ClientUserNameData.get(client_id);
    if (login_characters !== undefined) {
        //TODO 持久化所有在线角色的最新数据
        let all_characters = G.Characters.get_all_characters(username);
        for (let index = 0; index < all_characters.length; index++) {
            let characters = all_characters[index];
            let offline_time = Math.floor(Date.now() / 1000);
            characters["离线时间"] = offline_time;
            //帮派处理
            if (_GangDataCache.has(characters["BPID"])) {
                _GangDataCache.get(characters["BPID"])["成员数据"][characters["id"]]["离线时间"] = offline_time;
            }
            //队伍处理
            if(characters["队伍"] !== 0  && _TeamDataCache.has(characters["队伍"])){
                G.TeamUtils.remove_team_characters(characters["队伍"], characters["id"]);
            }
            // 持久化数据
            await G.Characters.update_characters_data_by_json_data(characters);
        }
    }
    
    //清理客户端角色缓存
    G.Characters.remove_all_characters_cache(username);

    //清理客户端账户相关缓存
    G.Accounts.clean_currrent_accounts_cache(client_id);
}